package com.trkj.service.wxy;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.wxy.ExamArrangeDao;
import com.trkj.dao.wxy.OverviewDao;
import com.trkj.dao.wxy.StaffInformationDao;
import com.trkj.pojo.Admission;
import com.trkj.pojo.DefinitionDept;
import com.trkj.pojo.ExamArrange;
import com.trkj.pojo.ExamPaper;
import com.trkj.pojo.StaffInformation;
import com.trkj.vo.wxy.OverviewPageVo;



@Service
@Transactional(rollbackFor = Exception.class)
public class OverviewService {
	@Autowired
	private OverviewDao overviewDao;
	@Autowired
	private StaffInformationDao staffInformationDao;
	
	@Autowired
	private ExamArrangeDao examArrangeDao;
	
	/**
	 * 查询所有分页考试安排概览
	 * @param page
	 * @param rows
	 * @return
	 */
	public List<OverviewPageVo> queryByOverviewPageVo(int page,int rows){
		List<Object[]> list = overviewDao.queryByOverView(new PageRequest(page-1, rows));
		
		List<OverviewPageVo> listOverviewPageVo = new ArrayList<>();
		if(list != null){
			for(Object[] objs: list){
				ExamArrange a= (ExamArrange) objs[0];
				ExamPaper e = (ExamPaper) objs[1];
				
				
				OverviewPageVo overviewPageVo = new OverviewPageVo();
				
				overviewPageVo.setArrangeId(a.getArrangeId());
				overviewPageVo.setArrangeName(a.getArrangeName());
				overviewPageVo.setArrangQualified(a.getArrangQualified());
				
				overviewPageVo.setClassSjName(e.getClassSjName());
				overviewPageVo.setEpStarttime(e.getEpStarttime());
				overviewPageVo.setEpEndtime(e.getEpEndtime());
				
				listOverviewPageVo.add(overviewPageVo);
			}
		
		}
		return listOverviewPageVo;
		
	}
	
	
	
	/**
	 * 查询所有分页员工概览
	 * @param page
	 * @param rows
	 * @return
	 */
	public List<OverviewPageVo> queryByOverviewPage(int page,int rows){
		List<Object[]> list = staffInformationDao.queryByOverViewStaff(new PageRequest(page-1, rows));
		
		List<OverviewPageVo> listOverviewPageVo = new ArrayList<>();
		if(list != null){
			for(Object[] objs: list){
				
				DefinitionDept d = (DefinitionDept) objs[1];
				StaffInformation s = (StaffInformation) objs[0];
				Admission a= (Admission) objs[2];
				
				OverviewPageVo overviewPageVo = new OverviewPageVo();
				
				overviewPageVo.setAdmId(a.getAdmId());
				overviewPageVo.setDefideName(d.getDefideName());
				overviewPageVo.setStainId(s.getStainId());
				
				overviewPageVo.setStainName(s.getStainName());
				
				listOverviewPageVo.add(overviewPageVo);
				
				System.out.println(list);
			}
		
		}
		return listOverviewPageVo;
		
	}
	
	
	/**
	 * 获取总记录数
	 * @return
	 */
	public long empByPageCount(){
		return overviewDao.count();
		
	}
	

}
